<template>
	<view>
		<cu-custom bgColor="bg-gradual-pink" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">测试数据上传</block>
		</cu-custom>
		<form>
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-green lg"  @click="selectivity">选择维护设备</button>
			</view>			
			
			<view class="cu-form-group">
				<view class="title">设备编号</view>
				<input readonly  name="input" v-model="myFormDataTest.deviceId"></input>
			</view>

			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">通电电位(mV):</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.pson}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.pson"></input>
				</view>
			</view>
			
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">断电电位(V):</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.psoff}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.psoff"></input>
				</view>
			</view>
			
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">交流电压(V):</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.av}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.av"></input>
				</view>
			</view>
			
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">自然电位(V):</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.sp}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.sp"></input>
				</view>
			</view>
			
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">试片直流电流(mA):</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.dc}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.dc"></input>
				</view>
			</view>
			
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">试片交流电流(mA):</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.ac}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.ac"></input>
				</view>
			</view>
			
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">牺牲阳极电位(V):</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.sap}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.sap"></input>
				</view>
			</view>
			
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">牺牲阳极保护电流(mA):</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.sac}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.sac"></input>
				</view>
			</view>
			
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">信号强度(dBm):</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.si}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.si"></input>
				</view>
			</view>
			
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">电池电压(V):</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.bv}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.bv"></input>
				</view>
			</view>
			
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">电池电量(%):</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.ba}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.ba"></input>
				</view>
			</view>
			
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">厂商信息:</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 40%;color: #00aa00;">{{arryObject.mf}}</text>
					<input style="width: 60%;" name="input" v-model="myFormDataTest.mf"></input>
				</view>
			</view>
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">时间戳:</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 100%;color: #00aa00;">{{arryObject.time}}</text>
				</view>
			</view>
			<view class="cu-form-group" style="width: 100%;">
				<view class="content" style="width: 35%">
					<text class="text-black title ">设备上报时间:</text>
				</view>
				<view class="propertyBox" style="width: 65%; flex-flow: row;justify-content: flex-start;display: flex;">
					<text style="width: 100%;color: #00aa00;">{{arryObject.createTime}}</text>
				</view>
			</view>

			<view class="cu-form-group">
				<view class="title">测试上传时间:</view>
				<view class="uni-list-cell-db">
					<picker mode="date" :value="myFormDataTest.reportTime" :start="startDate" :end="endDate" @change="bindDateChange">
						<view class="uni-input">{{myFormDataTest.reportTime}}</view>
					</picker>
					</view>
					<view class="uni-list-cell-db">
					<picker mode="time" :value="myFormDataTest.time" start="09:01" end="21:01" @change="bindTimeChange">
						<view class="uni-input">{{myFormDataTest.time}}</view>
					</picker>
				</view>
			</view>

			<view class="cu-form-group">
				<view class="title">备注：</view>
				<textarea  placeholder="" name="input"  v-model="myFormDataTest.remark"></textarea>
			</view>

			<view class="padding flex flex-direction">
				<button class="cu-btn bg-blue lg"  @click="onSubmit">提交</button>
			</view>
		</form>
	</view>
</template>

<script>
	import appSelect from '@/components/my-componets/appSelect.vue'


	export default {
		components:{
			appSelect
		 },
		data() {
			const currentDate = this.getDate({
			    format: true
			})
			return {
				flag:false,
				tempFileList:[],
				index: -1,
				switchC: true,
				type:"1",
				selected:[],
				cameraIndex: 0,
				showVideo:false,
				arryObject:{

				},
				myFormDataTest:{
					deviceId:'',//系统设备编号
					ybnbId:'',
					reportTime:currentDate,
					time: '12:01',
					pson:'',
					psoff:'',
					av:'',
					sp:'',
					dc:'',
					ac:'',
					sap:'',
					sac:'',	
					si:'',
					bv:'',
					ba:'',
					mf:'',
					remark:'',
				},
			};
		},
		onLoad: function (option) {

			const annItem = JSON.parse(decodeURIComponent(option.item));
			this.myFormDataTest.deviceId=annItem
			this.myFormDataTest.time = this.getTime();
			
		},
	
		onShow() {
		    let pages = getCurrentPages();
		    if (pages[pages.length - 1].$vm.schoolName) {
		        this.arryObject = pages[pages.length - 1].$vm.arryObject
		    }
			this.myFormDataTest.ybnbId=this.arryObject.id
		},

		computed: {
        startDate() {
            return this.getDate('start');
        },
        endDate() {
            return this.getDate('end');
        }
		},
		
		methods: {
			
			onSubmit() {
				
				let myForm = this.myFormDataTest
				console.log("myForm",myForm)
			
				this.$tip.loading();
				this.$http.put('/two/cathodeNBTestAdd',myForm).then(res=>{
					console.log(res)
					this.$tip.loaded();
					if (res.data.success){
						this.$tip.toast('提交成功')
						uni.navigateBack({
						  delta:1
						});
					}
				}).catch(()=>{
					this.$tip.loaded();
					this.$tip.error('提交失败')
				});
				
			},
			
			
			selectivity(){
				
				uni.navigateTo({
						url: '/pages/cathode/cathodeNBHischoice?item='+ encodeURIComponent(JSON.stringify(this.myFormDataTest.deviceId))
						
				});
			},
			getTime:function(){
						var date = new Date(),
						year = date.getFullYear(),
						month = date.getMonth() + 1,
						day = date.getDate(),
						hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
						minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
						second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
						month >= 1 && month <= 9 ? (month = "0" + month) : "";
						day >= 0 && day <= 9 ? (day = "0" + day) : "";
						var timer = hour + ':' + minute + ':' + second;
						return timer;
					},
			bindTimeChange: function(e) {
				            this.myFormDataTest.time = e.detail.value
				        },
			getDate(type) {
			    const date = new Date();
			    let year = date.getFullYear();
			    let month = date.getMonth() + 1;
			    let day = date.getDate();
			
			    if (type === 'start') {
			        year = year - 60;
			    } else if (type === 'end') {
			        year = year + 2;
			    }
			    month = month > 9 ? month : '0' + month;
			    day = day > 9 ? day : '0' + day;
			    return `${year}-${month}-${day}`;
			},
			bindDateChange: function(e) {
				 this.myFormDataTest.reportTime = e.detail.value
			},

		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
	.burst-wrap{
	    width: 100%;
	    height: 100%;
	}
	.burst-wrap .burst-wrap-bg>view{
	    width: 90%;
	    height: 100%;
	    margin: 0 auto;
	    position: absolute;
	    top: 65upx;
	    left: 0;
	    right: 0;
	}

	.form-item{
	    width: 100%;
	}
	.form-item textarea{
	    display: block;
	    height: 220upx;
	    width: 100%;
	    color: #AAAAAA;
	    font-size: 28upx;
	}
	.uni-uploader__file,.uploader_video{
	    position: relative;
	    z-index: 1;
	    width: 200upx;
	    height: 200upx;
	}
	.uni-uploader__img {
	    width: 200upx;
	    height: 200upx;
	}
	.icon-cuo {
	    position: absolute;
	    right: 0;
	    top: 5upx;
	    background: linear-gradient(90deg,rgba(251,91,80,1) 0%,rgba(240,45,51,1) 100%);
	    color: #FFFFFF;
	    z-index: 999;
	    border-top-right-radius: 20upx;
	    border-bottom-left-radius: 20upx;
	}
	.video{
	    width: 100%;
	    height: 100%;
	}

	.login-input-box{
	    position: relative;
	    border-bottom: 1upx solid #EEEEEE;
	}
	.login-input-box .forget,.login-input-box .phone{
	    position: absolute;
	    top: 0;
	    height: 100%;
	    z-index: 100;
	}
	.login-input-box .phone{
	    width: 100upx;
	    left: 0;
	    color: #666666;
	    font-weight: bold;
	}
	.login-input-box .phone-input{
	    padding-left: 100upx;
	}
	.address-wrap,.open-info{
	    margin-top: 20upx;
	}
	.open-info>view:last-child{
	    font-size: 28upx;
	    color: #999999;
	}
	.address-wrap .address {
	    background: #F2F2F2;
	    border-radius: 40upx;
	    padding: 0 20upx;
	}
	.user-set-btn{
	    margin: 40upx;
	    background: linear-gradient(90deg,rgba(251,91,80,1) 0%,rgba(240,45,51,1) 100%);
	    color: #FFFFFF;
	    text-align: center;
	    height: 88upx;
	    line-height: 88upx;
	}

</style>
